!define PRODUCT_NAME "LeisureCenter Updater"
!define PRODUCT_VERSION "0.1"
!define PRODUCT_PUBLISHER "cfagn"
!define PUBLISHER_WEB_SITE "http://www.cfagn.net"
!define PRODUCT_WEB_SITE "${PUBLISHER_WEB_SITE}/leisurecenter"
!define PRODUCT_UPDATER "LeisureCenter-updater.exe"
!define PRODUCT_EXECUTABLE "LeisureCenter.exe"

SetCompressor lzma

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "bin\Update.exe"
InstallDir "$PROGRAMFILES\cfagn\LeisureCenter"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "InstallDir"
ShowInstDetails hide
ShowUnInstDetails hide
BrandingText "${PUBLISHER_WEB_SITE}"
SilentInstall silent

; GetParameters
 ; input, none
 ; output, top of stack (replaces, with e.g. whatever)
 ; modifies no other variables.

 Function GetParameters

   Push $R0
   Push $R1
   Push $R2
   Push $R3

   StrCpy $R2 1
   StrLen $R3 $CMDLINE

   ;Check for quote or space
   StrCpy $R0 $CMDLINE $R2
   StrCmp $R0 '"' 0 +3
     StrCpy $R1 '"'
     Goto loop
   StrCpy $R1 " "

   loop:
     IntOp $R2 $R2 + 1
     StrCpy $R0 $CMDLINE 1 $R2
     StrCmp $R0 $R1 get
     StrCmp $R2 $R3 get
     Goto loop

   get:
     IntOp $R2 $R2 + 1
     StrCpy $R0 $CMDLINE 1 $R2
     StrCmp $R0 " " get
     StrCpy $R0 $CMDLINE "" $R2

   Pop $R3
   Pop $R2
   Pop $R1
   Exch $R0

 FunctionEnd
 
Section -Download
  StrCpy $1 "$TEMP\${PRODUCT_UPDATER}"
  NSISDl::download "${PRODUCT_WEB_SITE}/${PRODUCT_UPDATER}" "$1"
  Pop $0
  StrCmp $0 success success
  ;failed:
    Exec '"${PRODUCT_EXECUTABLE}" -updatefailed'
    Abort
  success:
    Call GetParameters
    Pop $2
    Exec '"$1" $2'
SectionEnd

